#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
using namespace std; using ll = long long;
constexpr int N=0;
int main(){
	Fin("bishop.in"); Fout("bishop.out");
	ios::sync_with_stdio(0); cin.tie(0);
	int n,m; cin>>n>>m;
	int SWAP=0; if(n>m) SWAP=1,swap(n,m);
	auto DO=[&](int x,int y){
		// static set<int> A,B;
		// assert(!A.count(x-y)&&!B.count(x+y));
		// A.insert(x-y); B.insert(x+y);
		if(!SWAP) cout<<x<<' '<<y<<'\n'; else cout<<y<<' '<<x<<'\n';
	};
	if(n==1&&m==1){
		cout<<"1\n"; cout<<"1 1\n";
	}
	else if(n==m){
		cout<<n+m-2<<'\n';
		For(i,1,n) DO(i,1);
		For(i,2,n-1) DO(i,n);
	}
	else{
		cout<<n+m-1-(n%2==0&&m%2==0)<<'\n';
		For(i,1,n) DO(i,1),DO(i,m);
		if(n&1){
			For(i,n/2+2,m-n/2-1) DO(n/2+1,i);
		}
		else{
			for(int i=n/2+2;i<=m-n/2-1;i+=2) DO(n/2,i),DO(n/2+1,i);
		}
	}
	return 0;
}